package io.renren.service.impl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.dao.SeatEslDao;
import io.renren.entity.SeatEslEntity;
import io.renren.service.SeatEslService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("seatEslService")
public class SeatEslServiceImpl extends ServiceImpl<SeatEslDao, SeatEslEntity> implements SeatEslService {
    @Autowired
    private SeatEslDao seatEslDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SeatEslEntity> page = this.page(
                new Query<SeatEslEntity>().getPage(params),
                new QueryWrapper<SeatEslEntity>()
        );

        return new PageUtils(page);
    }

    public SeatEslEntity queryBySeatId(Long seatId) {
        SeatEslEntity seatEslEntity = new SeatEslEntity();

        if (seatId != null && seatId != 0) {
            seatEslEntity = seatEslDao.selectOne(new QueryWrapper<SeatEslEntity>()
                    .eq("seat_id", seatId));
        }

        return seatEslEntity;
    }

    public SeatEslEntity queryByEslId(String eslId) {
        return seatEslDao.selectOne(new QueryWrapper<SeatEslEntity>()
                .eq(eslId != null, "esl_id", eslId)
        );
    }


}
